package com.retail.system.controller;

import com.retail.core.common.AbstractCommonController;
import com.retail.core.entity.ParamReq;
import com.retail.core.entity.result.PageResult;
import com.retail.core.entity.result.Result;
import com.retail.global.annon.TraceLog;
import com.retail.global.security.LoginUserUtil;
import com.retail.system.entity.request.LoginLogRequest;
import com.retail.system.entity.vo.LoginLogVo;
import com.retail.system.service.LoginLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* 登录日志 API
* @author Administrator
*/
@Api(tags = "登录日志 API")
@RestController
@RequestMapping("/loginLog")
public class LoginLogController extends AbstractCommonController<LoginLogService, LoginLogRequest, LoginLogVo>{

    private final LoginLogService loginLogService;

    public LoginLogController(LoginLogService loginLogService) {
        this.loginLogService = loginLogService;
    }

    @TraceLog()
    @ApiOperation("详情")
    @GetMapping("{id}")
    public Result getModel(@PathVariable("id") Long id) {
        return super.getModel(loginLogService, id);
    }

    @TraceLog()
    @PostMapping
    @ApiOperation("保存登录日志")
    public Result<Integer> save(@RequestBody LoginLogRequest request) {
        return super.save(loginLogService, request);
    }

    @TraceLog()
    @PutMapping
    @ApiOperation("更新登录日志")
    public Result<Integer> update(@RequestBody LoginLogRequest request) {
        return super.update(loginLogService, request);
    }

    @TraceLog()
    @PostMapping("listPage")
    @ApiOperation("登录日志-查询")
    public Result<List<LoginLogVo>> listPage(@RequestBody ParamReq<LoginLogRequest> req)  {
        return super.listPage(loginLogService, req);
    }

    @TraceLog()
    @PostMapping("countPage")
    @ApiOperation("登录日志-统计")
    public Result<Integer> countPage(@RequestBody ParamReq<LoginLogRequest> req)  {
        return super.countPage(loginLogService, req);
    }

    @TraceLog()
    @PostMapping("page")
    @ApiOperation("登录日志-分页数据")
    public Result<PageResult> page(@RequestBody ParamReq<LoginLogRequest> req)  {
        return super.page(loginLogService, req);
    }

    @TraceLog()
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除登录日志")
    public Result<Integer> delete(@PathVariable("id") Long id) {
        return super.delete(loginLogService, id);
    }

    @TraceLog()
    @ApiOperation("批量删除登录日志")
    @DeleteMapping("{ids}")
    public Result<Integer> batchDelete(@PathVariable("ids") List<Long> ids) {
        return super.batchDelete(loginLogService, ids);
    }

    @Override
    public Long getLoginUserId() {
        return LoginUserUtil.getUserId();
    }
}
